Skip to content

Scotland | ITP JAN-2026 | Tuan Nguyen | Sprint 3 | 2- Practice-tdd#1258

Open
Jacknguyen4438 wants to merge 3 commits intoCodeYourFuture:mainfrom
Jacknguyen4438:Jest-test-case-sprint-3B
Open

Scotland | ITP JAN-2026 | Tuan Nguyen | Sprint 3 | 2- Practice-tdd#1258
Jacknguyen4438 wants to merge 3 commits intoCodeYourFuture:mainfrom
Jacknguyen4438:Jest-test-case-sprint-3B

Conversation

@Jacknguyen4438
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

I have done practice and fully understand how to write a test for both normal JS and Jest test.

Questions

No Question.

@Jacknguyen4438 Jacknguyen4438 added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels Mar 13, 2026
Comment on lines +8 to +10
if (findCharacters.length < 1) {
throw new Error("findCharacters must be a single character");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is findCharacters allowed to be more than one characters?

Copy link
Author

@Jacknguyen4438 Jacknguyen4438 Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for feed back, I see that I have make some validation error. I can see that instead of validation for just a specific character. So instead I will change this test so that is can check correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could consider testing a few more samples in this script - higher chance to detect bugs in code.

The original specification did not clearly state whether the character match should be case-sensitive.
Most people would probably assume that it is, but to demonstrate our understanding or clarify the assumption we made,
we could add test cases to convey this. For examples,

  • A case to show that the match is case sensitive
  • A case to show that the function is expected to work also for non-alphabets

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjyuan Thank you for the suggestion here is my jest test case for this 2 scenario:

// Scenario: Case-sensitive matching
// Given a string containing both uppercase and lowercase versions of a letter,
// When the function is called with a lowercase character,
// Then it should only count the lowercase occurrences.

test("should treat character matching as case-sensitive", () => {
expect(countChar("AaAa","A")).toEqual(2);
});

// Scenario: Non-alphabet characters
// Given a string containing digits and symbols,
// When the function is called with a non-alphabet character,
// Then it should correctly count occurrences of that character.

test("should count occurrences of non-alphabet characters", () => {
expect(countChar("1-2-3-1-1","1")).toEqual(3);
});

Comment on lines +10 to +18
if(num % 100 === 11 ||num % 100 === 12 || num % 100 === 13 ){
return `${num}th`;
}
switch( true ){
case num % 10 === 1 : return `${num}st`;
case num % 10 === 2 : return `${num}nd`;
case num % 10 === 3 : return `${num}rd`;
default : return `${num}th`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you look up the pros and cons between these two styles of expressing the code?

  if(num % 100 === 11 ||num % 100 === 12 || num % 100 === 13 ){
  const lastTwoDigits = num % 100;
  if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13 ) {

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjyuan Thank you for the feed back,

I see that that for the first line the main pro is that :

  • The pros is that the code shorter, no extra variable and is good for when 1 argument pass to each condition.
  • The cons is that the code it harder to understand for some new beginner and might caught with unexpected error. Also the argument num is now pass 3 time for each condition and it can cause issue if the code is broke outside the function.

For the second line I see that:

  • The pros of this line is that is more solid and safer then the first line. It help other coder or beginner to understand the code easier. Also the value now store inside a container that can be used safely and if need be can be change later.
    The cons for this line of code as far as I can see is that is only add 1 more line of code.

So after I see both Pros and cons of these 2 line, understand for the best I will used the second line of code since is more save and easier to change and fix. I will make this change inside my code. Thank you.

}

// This allow float number to be round into it nearest integer.
num = Math.round(num);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you decide to round the numbers with decimal places? Why not reject them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one I, the main reason is that since I would like to for the function to work even is the user pass a float number value. When pass inside the function the argument num will automatically will be round to their nearest number then do the reminder. But I see now is might caught the issue since it will return not what the user put in so I will max change that reject the decimal value.

// Case 5: All other numbers
// When the number does not end with 1, 2, or 3,
// Then the function should append "th".
test("should append 'th' for all other numbers", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a test fails with the message "... all other numbers", it may be unclear what "other numbers" actually refers to.
Can you revise the test description to make it more informative?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feed back I will fix it right away

Comment on lines +6 to +9
switch (true){
case repeatCount === 0 : return "";
default: return fullString.repeat(repeatCount) ;
};
Copy link
Contributor

@cjyuan cjyuan Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this writing style?

if (repeatCount === 0) return "":

return fullString.repeat(repeatCount);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the reply , I think that if I used the same method as you using with this line code. It will run and return the value just fine since is a if else statement but more shorthand compact. I understand that by using switch case is make make the code look better but in long term can cause some issue in the long run. So for the best I will try this if else style for easier reading and maintain the code.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 14, 2026
@Jacknguyen4438
Copy link
Author

@cjyuan Hello thank you for the review, I see there are many part that need to be fix and improve. I will check all 5 part that you would like me to explain and fix each of them. When I finish I will mention you again to ask for a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Structuring-And-Testing-Data The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants